package com.wyy.springbootgraphql.resolver;

import com.wyy.springbootgraphql.beans.Post;
import com.wyy.springbootgraphql.beans.PostInput;
import graphql.kickstart.tools.GraphQLMutationResolver;
import org.springframework.stereotype.Service;

@Service
public class PostMutationService implements GraphQLMutationResolver {

    // 发帖
    public Post addPost(PostInput postInput){
        Post post = new Post(postInput.getPostId(), postInput.getTitle(), postInput.getText());
        return post;
    }

    // 封禁帖子
    public Boolean BannedPost(String id){
        if ("001".equals(id)){
            Post post = new Post("123", "1123", "23214");
            post.setFlag(true);
            return true;
        }else
            return false;
    }

    // 修改帖子
    public Post updatePost(PostInput postInput){
        if ("001".equals(postInput.getPostId())){
            Post post = new Post(postInput.getPostId(), postInput.getTitle(), postInput.getText());
            return post;
        } else
            return null;
    }

    // 删除帖子
    public Boolean deletePost(String id){
        if ("001".equals(id)){
            return true;
        }else
            return false;
    }

}
